
/* this file is for Chen& Mason migrant worker protest paper*/ 
/* Clear all junk out of memory */
clear

/* Turn off the crazy feature that freezes the Stata output screen */
set more off


/* load CGSS2010 data */
use "D:\Survey datasets\CGSS survey\CGSS2010\CGSS2010.dta", clear



/*the variable protest1 is from d12c, which is about participation of protest*/
tabulate d12c
tabulate d12c, nolab

gen protest1=.
replace protest1=1 if d12c==1
replace protest1=1 if d12c==2
replace protest1=0 if d12c==3
replace protest1=0 if d12c==4
replace protest1=0 if d12c==5
replace protest1=0 if d12c==6
tabulate protest1


/*this is to answer reviewer5*/
gen Protest11=.
replace Protest11=1 if d12c==1
replace Protest11=1 if d12c==2
replace Protest11=0 if Protest11==.
tab Protest11

/*the variable protest2 is from d207, which is about participation of protest,too*/
tabulate d207
tabulate d207, nolab

gen protest2=.
replace protest2=1 if d207==1
replace protest2=0 if d207==2
tabulate protest2

/*the variable Protest is from variables protest1 and protest2*/
gen Protest=.
replace Protest=1 if protest1==1 | protest2==1 
replace Protest=0 if protest1==0 & protest2==0
replace Protest=0 if protest1==0 & protest2==.
replace Protest=0 if protest1==. & protest2==0
tabulate Protest

/*this is for resubmission to Asian Survey*/
gen protest3=.
replace protest3=1 if d12c==1
replace protest3=1 if d12c==2
replace protest3=1 if d12c==3
replace protest3=1 if d12c==4
replace protest3=0 if d12c==5
replace protest3=0 if d12c==6

tabulate protest3

gen ProtestAS=.
replace ProtestAS=1 if protest3==1 | protest2==1 
replace ProtestAS=0 if protest3==0 & protest2==0
replace ProtestAS=0 if protest3==0 & protest2==.
replace ProtestAS=0 if protest3==. & protest2==0
tabulate ProtestAS



gen ProtestOrder=.
replace ProtestOrder=5 if d12c==1
replace ProtestOrder=4 if d12c==2
replace ProtestOrder=3 if d12c==3
replace ProtestOrder=2 if d12c==4
replace ProtestOrder=1 if d12c==5 | d12c==6 | d12c==.




/*the variable petition1 is from d203*/
tabulate d203
tabulate d203, nolab

gen petition1=.
replace petition1=1 if d203==1
replace petition1=0 if d203==2
tabulate petition1

/*the variable petition2 is from d13b05*/
tabulate d13b05
tabulate d13b05, nolab 
 
gen petition2=.
replace petition2=1 if d13b05==1
replace petition2=0 if d13b05==0
tabulate petition2

gen Petition=.
replace Petition=1 if petition1==1 | petition2==1
replace Petition=0 if petition1==0 & petition2==0
replace Petition=0 if petition1==0 & petition2==.
replace Petition=0 if petition1==. & petition2==0
tab Petition



gen both=.
replace both=1 if Protest==1& Petition==1
replace both=0 if Protest==1& Petition==0
replace both=0 if Protest==0& Petition==1
replace both=0 if Protest==0& Petition==0

gen YprotestNpetition=.
replace YprotestNpetition=1 if Protest==1 & Petition==0
replace YprotestNpetition=0 if Protest==1 & Petition==1
replace YprotestNpetition=0 if Protest==0 & Petition==1
replace YprotestNpetition=0 if Protest==0 & Petition==0

gen NprotestYpetition=.
replace NprotestYpetition=1 if Protest==0 & Petition==1
replace NprotestYpetition=0 if Protest==1 & Petition==1
replace NprotestYpetition=0 if Protest==1 & Petition==0
replace NprotestYpetition=0 if Protest==0 & Petition==0

gen NN=.
replace NN=1 if Protest==0 & Petition==0
replace NN=0 if Protest==1 & Petition==1
replace NN=0 if Protest==1 & Petition==0
replace NN=0 if Protest==0 & Petition==1

gen Participation=.
replace Participation=4 if Protest==1 & Petition==1
replace Participation=3 if Protest==1 & Petition==0
replace Participation=2 if Protest==0 & Petition==1
replace Participation=1 if Protest==0 & Petition==0




/*the variable CA is from variables Protest and Petition*/
gen CA=.
replace CA=1 if Protest==1 | Petition==1
replace CA=0 if Protest==0 & Petition==0
tab CA

/*my brain is not working well now. Therefore, simply keep this and think it twice later*/
gen NofCA = protest1+ protest2 + petition1 + petition2
tab NofCA

/*create several demographic variables*/

/*create variable about gender. male=1;female=0*/
tabulate a2
tabulate a2, nolab
gen male=.
replace male=1 if a2==1
replace male=0 if a2==2
tabulate male

/*create variable education*/
tabulate a7a
describe a7a
label drop a7alab
tabulate a7a
gen education=a7a
tabulate education
replace education=. if edu<1
replace education=. if edu>13
tabulate education



/* create variables about ethnicity*/
tabulate a4
describe a4
label drop a4lab
tabulate a4

gen minority=.
replace minority=0 if a4==1
replace minority=1 if a4==2
replace minority=1 if a4==3
replace minority=1 if a4==4
replace minority=1 if a4==5
replace minority=1 if a4==6
replace minority=1 if a4==7
replace minority=1 if a4==8






/*the following variables come from Schussman and Soule(2005)*/
/* create variable age*/
describe a3a
gen yearofbirth=a3a
tabulate yearofbirth
replace yearofbirth=. if a3a< 1914
gen age=2011-yearofbirth
tabulate age

/* create variable marriage*/
tab a69
tab a69, nolab

gen married=.
replace married=1 if a69==3
replace married=0 if a69==1
replace married=0 if a69==2
replace married=0 if a69==4
replace married=0 if a69==5
replace married=0 if a69==6
tab married

/* create variable political knowledge*/
tab d8
tab d8, nolab

gen poliknow=.
replace poliknow=1 if d8==1
replace poliknow=0 if d8==2
tab poliknow

/* create deprived actor variable*/
/* create variable personal annual income*/
tabulate a8a
gen income=a8a/1000
replace income=. if income>6000

/*create relative deprivation variable*/
/*create variable unfairtreatment*/
tabulate d13a
describe d13a
label drop  d13alab
tabulate d13a
gen unfairtreatment=.
replace unfairtreatment=1 if d13a==1
replace unfairtreatment=0 if d13a==2
tabulate unfairtreatment

/*create variable incomefair*/
tabulate d5a
tabulate d5a, nolab

gen incomefair=.
replace incomefair=1 if d5a==1
replace incomefair=2 if d5a==2
replace incomefair=3 if d5a==3
replace incomefair=4 if d5a==4
replace incomefair=5 if d5a==5
tabulate incomefair

/*create variable incomeunfair; this also might be easier*/
tabulate d5a
tabulate d5a, nolab

gen incomeunfair=.
replace incomeunfair=5 if d5a==1
replace incomeunfair=4 if d5a==2
replace incomeunfair=3 if d5a==3
replace incomeunfair=2 if d5a==4
replace incomeunfair=1 if d5a==5
tabulate incomeunfair









/*create variable fairness*/
gen fairness=.
replace fairness=1 if a35==1
replace fairness=2 if a35==2
replace fairness=3 if a35==3
replace fairness=4 if a35==4
replace fairness=5 if a35==5
tabulate fairness




/*create variable unfairness; this should be easier to interpret*/
gen unfairness=.
replace unfairness=5 if a35==1
replace unfairness=4 if a35==2
replace unfairness=3 if a35==3
replace unfairness=2 if a35==4
replace unfairness=1 if a35==5
tabulate unfairness






/*create variables about political trust*/

gen trustCJ=.
replace trustCJ=1 if d301==1
replace trustCJ=2 if d301==2
replace trustCJ=3 if d301==3
replace trustCJ=4 if d301==4
replace trustCJ=5 if d301==5

gen trustCG=.
replace trustCG=1 if d302==1
replace trustCG=2 if d302==2
replace trustCG=3 if d302==3
replace trustCG=4 if d302==4
replace trustCG=5 if d302==5

gen trustLG=.
replace trustLG=1 if d303==1
replace trustLG=2 if d303==2
replace trustLG=3 if d303==3
replace trustLG=4 if d303==4
replace trustLG=5 if d303==5

gen trustMT=.
replace trustMT=1 if d304==1
replace trustMT=2 if d304==2
replace trustMT=3 if d304==3
replace trustMT=4 if d304==4
replace trustMT=5 if d304==5

gen trustPL=.
replace trustPL=1 if d305==1
replace trustPL=2 if d305==2
replace trustPL=3 if d305==3
replace trustPL=4 if d305==4
replace trustPL=5 if d305==5

gen trustCM=.
replace trustCM=1 if d306==1
replace trustCM=2 if d306==2
replace trustCM=3 if d306==3
replace trustCM=4 if d306==4
replace trustCM=5 if d306==5

gen trustLM=.
replace trustLM=1 if d307==1
replace trustLM=2 if d307==2
replace trustLM=3 if d307==3
replace trustLM=4 if d307==4
replace trustLM=5 if d307==5

gen trustCN=.
replace trustCN=1 if d310==1
replace trustCN=2 if d310==2
replace trustCN=3 if d310==3
replace trustCN=4 if d310==4
replace trustCN=5 if d310==5


gen trustDM=.
replace trustDM=trustCM-trustLM

gen trustDG=.
replace trustDG=trustCG-trustLG






/*create variable Social Status now*/
tabulate a43a
describe a43a
label drop a43lab
tabulate a43a

gen SSN=.
replace SSN=1 if a43a==1
replace SSN=2 if a43a==2
replace SSN=3 if a43a==3
replace SSN=4 if a43a==4
replace SSN=5 if a43a==5
replace SSN=6 if a43a==6
replace SSN=7 if a43a==7
replace SSN=8 if a43a==8
replace SSN=9 if a43a==9
replace SSN=10 if a43a==10


/*create variable Social Status 10 years ago*/
tabulate a43b
describe a43b
label drop a43blab
tabulate a43b
gen SSB=.
replace SSB=1 if a43b==1
replace SSB=2 if a43b==2
replace SSB=3 if a43b==3
replace SSB=4 if a43b==4
replace SSB=5 if a43b==5
replace SSB=6 if a43b==6
replace SSB=7 if a43b==7
replace SSB=8 if a43b==8
replace SSB=9 if a43b==9
replace SSB=10 if a43b==10

/*create variable Social Status in 10 years*/
tabulate a43c
describe a43c
label drop a43clab
tabulate a43c
gen SSF=.
replace SSF=1 if a43c==1
replace SSF=2 if a43c==2
replace SSF=3 if a43c==3
replace SSF=4 if a43c==4
replace SSF=5 if a43c==5
replace SSF=6 if a43c==6
replace SSF=7 if a43c==7
replace SSF=8 if a43c==8
replace SSF=9 if a43c==9
replace SSF=10 if a43c==10


/*create variables about comparisons*/

gen compareNB=SSN-SSB
gen better1=.
gen worse1=.
gen same1=.

replace better1=1 if compareNB>=1
replace better1=0 if compareNB==0 | compareNB<=-1

replace worse1=1 if compareNB<=-1
replace worse1=0 if compareNB>=0

replace same1=1 if compareNB==0
replace same1=0 if compareNB>=1 | compareNB<=-1

gen compareFN=SSF-SSN
gen better2=.
gen worse2=.
gen same2=.

replace better2=1 if compareFN>=1
replace better2=0 if compareFN==0 | compareFN<=-1

replace worse2=1 if compareFN<=-1
replace worse2=0 if compareFN>=0

replace same2=1 if compareFN==0
replace same2=0 if compareFN>=1 | compareFN<=-1

gen compareFB=SSF-SSB
gen better3=.
gen worse3=.
gen same3=.

replace better3=1 if compareFB>=1
replace better3=0 if compareFB==0 | compareFB<=-1

replace worse3=1 if compareFB<=-1
replace worse3=0 if compareFB>=0

replace same3=1 if compareFB==0
replace same3=0 if compareFB>=1 | compareFB<=-1




gen CompareNB=SSN-SSB
gen better=.
replace better=1 if CompareNB>=1
replace better=0 if CompareNB==0 | CompareNB<1

/*create variables about voting behavior*/
tab d16, nolab

gen voted=.
replace voted=1 if d16==1
replace voted=0 if d16==2



/*Chapter 3, The FIRST EMPIRICAL CHAPTER*/

/*The first set of my IVs is about the what kind of job they have(had); 
it is all about the job, regardless of their hukoues*/

tabulate a58
tabulate a58, nolab

/* first, the respondent's occupation*/
gen notPeasant1=.
replace notPeasant1=1 if a58==1
replace notPeasant1=0 if a58==2
replace notPeasant1=0 if a58==3
replace notPeasant1=0 if a58==4
replace notPeasant1=0 if a58==5
replace notPeasant1=0 if a58==6
tab notPeasant1

gen Peasant1=.
replace Peasant1=0 if a58==1
replace Peasant1=1 if a58==2
replace Peasant1=1 if a58==3
replace Peasant1=0 if a58==4
replace Peasant1=0 if a58==5
replace Peasant1=0 if a58==6
tab Peasant1

gen Unemployed1=.
replace Unemployed1=0 if a58==1
replace Unemployed1=0 if a58==2
replace Unemployed1=0 if a58==3
replace Unemployed1=1 if a58==4
replace Unemployed1=1 if a58==5
replace Unemployed1=0 if a58==6
tab Unemployed1

gen neverwork1=.
replace neverwork1=0 if a58==1
replace neverwork1=0 if a58==2
replace neverwork1=0 if a58==3
replace neverwork1=0 if a58==4
replace neverwork1=0 if a58==5
replace neverwork1=1 if a58==6
tab neverwork1

/*create the second level of variable: for those who are (were) not peasants, whether or not they are (were) labor workers */

tab a59a
describe a59a
label drop lab12
tab a59a

gen Peasant2=Peasant1
gen Unemployed2=Unemployed1
gen neverwork2=neverwork1

gen Entrepreneur2=.
replace Entrepreneur2=1 if a58==1 & a59a==1 
replace Entrepreneur2=1 if a58==1 & a59a==2 
replace Entrepreneur2=0 if a58==1 & a59a==3 
replace Entrepreneur2=0 if a58==1 & a59a==4 
replace Entrepreneur2=0 if a58==1 & a59a==5 
replace Entrepreneur2=1 if a58==1 & a59a==6 
replace Entrepreneur2=1 if a58==1 & a59a==7 
replace Entrepreneur2=0 if a58==1 & a59a==8 
replace Entrepreneur2=0 if a58==1 & a59a==9 
tabulate Entrepreneur2

gen Worker2=.
replace Worker2=0 if a58==1 & a59a==1 
replace Worker2=0 if a58==1 & a59a==2 
replace Worker2=1 if a58==1 & a59a==3 
replace Worker2=1 if a58==1 & a59a==4 
replace Worker2=1 if a58==1 & a59a==5 
replace Worker2=0 if a58==1 & a59a==6 
replace Worker2=0 if a58==1 & a59a==7 
replace Worker2=0 if a58==1 & a59a==8 
replace Worker2=0 if a58==1 & a59a==9 
tabulate Worker2


/*it should be freelance*/
gen Selfemployedother2=.
replace Selfemployedother2=0 if a58==1 & a59a==1 
replace Selfemployedother2=0 if a58==1 & a59a==2 
replace Selfemployedother2=0 if a58==1 & a59a==3 
replace Selfemployedother2=0 if a58==1 & a59a==4 
replace Selfemployedother2=0 if a58==1 & a59a==5 
replace Selfemployedother2=0 if a58==1 & a59a==6 
replace Selfemployedother2=0 if a58==1 & a59a==7 
replace Selfemployedother2=1 if a58==1 & a59a==8 
replace Selfemployedother2=1 if a58==1 & a59a==9 
tab Selfemployedother2



replace Entrepreneur2=0 if Peasant2==1 
replace Entrepreneur2=0 if Unemployed2==1 
replace Entrepreneur2=0 if neverwork2==1 
tab Entrepreneur2


replace Worker2=0 if Peasant2==1
replace Worker2=0 if Unemployed2==1 
replace Worker2=0 if neverwork2==1 
tab Worker2

replace Selfemployedother2=0 if Peasant2==1
replace Selfemployedother2=0 if Unemployed2==1
replace Selfemployedother2=0 if neverwork2==1
tab Selfemployedother2

gen occupation2=.
replace occupation2=1 if Peasant2==1
replace occupation2=2 if Worker2==1
replace occupation2=3 if Entrepreneur2==1
replace occupation2=4 if Selfemployedother2==1
replace occupation2=5 if Unemployed2==1
replace occupation2=6 if neverwork2==1


/*create the third level of variable: disagregate worker2*/
/*these variables are for Chpater 4, the second empirical chapter*/
tab a59k, nolab

gen SOEworker3=.
replace SOEworker3=1 if (Worker2==1 & a59k==1)
replace SOEworker3=0 if (Worker2==1 & a59k==2)
replace SOEworker3=0 if (Worker2==1 & a59k==3)
replace SOEworker3=0 if (Worker2==1 & a59k==4)
replace SOEworker3=0 if (Worker2==1 & a59k==5)
replace SOEworker3=0 if (Worker2==1 & a59k==6)
replace SOEworker3=0 if (Worker2==1 & a59k==-3)
replace SOEworker3=0 if (Worker2==1 & a59k==-2)
replace SOEworker3=0 if (Worker2==1 & a59k==-1)
tab SOEworker3

gen TVEworker3=.
replace TVEworker3=0 if (Worker2==1 & a59k==1)
replace TVEworker3=1 if (Worker2==1 & a59k==2)
replace TVEworker3=0 if (Worker2==1 & a59k==3)
replace TVEworker3=0 if (Worker2==1 & a59k==4)
replace TVEworker3=0 if (Worker2==1 & a59k==5)
replace TVEworker3=0 if (Worker2==1 & a59k==6)
replace TVEworker3=0 if (Worker2==1 & a59k==-3)
replace TVEworker3=0 if (Worker2==1 & a59k==-2)
replace TVEworker3=0 if (Worker2==1 & a59k==-1)
tab TVEworker3

gen DPEworker3=.
replace DPEworker3=0 if (Worker2==1 & a59k==1)
replace DPEworker3=0 if (Worker2==1 & a59k==2)
replace DPEworker3=1 if (Worker2==1 & a59k==3)
replace DPEworker3=0 if (Worker2==1 & a59k==4)
replace DPEworker3=0 if (Worker2==1 & a59k==5)
replace DPEworker3=0 if (Worker2==1 & a59k==6)
replace DPEworker3=0 if (Worker2==1 & a59k==-3)
replace DPEworker3=0 if (Worker2==1 & a59k==-2)
replace DPEworker3=0 if (Worker2==1 & a59k==-1)
tab DPEworker3

gen FOEworker3=.
replace FOEworker3=0 if (Worker2==1 & a59k==1)
replace FOEworker3=0 if (Worker2==1 & a59k==2)
replace FOEworker3=0 if (Worker2==1 & a59k==3)
replace FOEworker3=1 if (Worker2==1 & a59k==4)
replace FOEworker3=1 if (Worker2==1 & a59k==5)
replace FOEworker3=0 if (Worker2==1 & a59k==6)
replace FOEworker3=0 if (Worker2==1 & a59k==-3)
replace FOEworker3=0 if (Worker2==1 & a59k==-2)
replace FOEworker3=0 if (Worker2==1 & a59k==-1)
tab FOEworker3

gen othersrefuse3=.
replace othersrefuse3=0 if (Worker2==1 & a59k==1)
replace othersrefuse3=0 if (Worker2==1 & a59k==2)
replace othersrefuse3=0 if (Worker2==1 & a59k==3)
replace othersrefuse3=0 if (Worker2==1 & a59k==4)
replace othersrefuse3=0 if (Worker2==1 & a59k==5)
replace othersrefuse3=1 if (Worker2==1 & a59k==6)
replace othersrefuse3=1 if (Worker2==1 & a59k==-3)
replace othersrefuse3=1 if (Worker2==1 & a59k==-2)
replace othersrefuse3=1 if (Worker2==1 & a59k==-1)
tab othersrefuse3

gen Peasant3=Peasant2
gen Entrepreneur3=Entrepreneur2
gen Selfemployedother3= Selfemployedother2
gen Unemployed3= Unemployed2
gen Neverwork3=neverwork2

replace SOEworker3=0 if Peasant2==1 
replace SOEworker3=0 if Entrepreneur3==1 
replace SOEworker3=0 if Selfemployedother3==1 
replace SOEworker3=0 if Unemployed3==1 
replace SOEworker3=0 if Neverwork3==1 
tab SOEworker3

replace TVEworker3=0 if Peasant2==1 
replace TVEworker3=0 if Entrepreneur3==1 
replace TVEworker3=0 if Selfemployedother3==1 
replace TVEworker3=0 if Unemployed3==1 
replace TVEworker3=0 if Neverwork3==1 
tab TVEworker3

replace DPEworker3=0 if Peasant2==1 
replace DPEworker3=0 if Entrepreneur3==1 
replace DPEworker3=0 if Selfemployedother3==1 
replace DPEworker3=0 if Unemployed3==1 
replace DPEworker3=0 if Neverwork3==1 
tab DPEworker3

replace FOEworker3=0 if Peasant2==1 
replace FOEworker3=0 if Entrepreneur3==1 
replace FOEworker3=0 if Selfemployedother3==1 
replace FOEworker3=0 if Unemployed3==1 
replace FOEworker3=0 if Neverwork3==1 
tab FOEworker3

replace othersrefuse3=0 if Peasant2==1 
replace othersrefuse3=0 if Entrepreneur3==1 
replace othersrefuse3=0 if Selfemployedother3==1 
replace othersrefuse3=0 if Unemployed3==1 
replace othersrefuse3=0 if Neverwork3==1 
tab othersrefuse3



gen occupation3=.
replace occupation3=1 if Peasant3==1
replace occupation3=2 if SOEworker3==1
replace occupation3=3 if TVEworker3==1
replace occupation3=4 if DPEworker3==1
replace occupation3=5 if FOEworker3==1
replace occupation3=6 if othersrefuse3==1
replace occupation3=7 if Entrepreneur3==1
replace occupation3=8 if Selfemployedother3==1
replace occupation3=9 if Unemployed3==1
replace occupation3=10 if Neverwork3==1



/*Chapter 5, the third EMPIRICAL CHAPTER*/

/*create variables to categorized workers into either migrant workers or non-migrant workers*/
/*first, create variables about hukou*/
tabulate a18
describe a18
label drop lab6
tabulate a18

gen AgriHukou=.
replace AgriHukou=1 if a18==1
replace AgriHukou=0 if a18==2
replace AgriHukou=0 if a18==3 
replace AgriHukou=0 if a18==4 
replace AgriHukou=0 if a18==5
tab AgriHukou


/*second, create variables about mirantworker*/
tabulate a21
describe a21
label drop a21lab
tab a21

gen outforwork=.
replace outforwork=0 if a21==1
replace outforwork=1 if a21==2
replace outforwork=1 if a21==3


gen urbanworker=.

replace urbanworker=1 if Worker2==1 & AgriHukou==0
replace urbanworker=0 if Worker2==1 & AgriHukou==1

gen migrantworker=.
replace migrantworker=1 if urbanworker==0& outforwork==1
replace migrantworker=0 if urbanworker==0& outforwork==0
replace migrantworker=0 if urbanworker==1

gen ruralworker=.
replace ruralworker=1 if urbanworker==0 & outforwork==0
replace ruralworker=0 if urbanworker==0 & outforwork==1
replace ruralworker=0 if urbanworker==1

gen workertype=.
replace workertype=1 if urbanworker==1
replace workertype=2 if migrantworker==1
replace workertype=3 if ruralworker==1
tab workertype





gen occupation5=.
replace occupation5=1 if migrantworker==1
replace occupation5=2 if urbanworker==1
replace occupation5=3 if ruralworker==1
replace occupation5=4 if Peasant3==1
replace occupation5=5 if Entrepreneur3==1
replace occupation5=5 if Selfemployedother3==1
replace occupation5=5 if Unemployed3==1
replace occupation5=5 if Neverwork3==1


gen Migrantworker5=.
gen Urbanworker5=.
gen Ruralworker5=.
gen Peasant5=.
gen Others5=.

replace Migrantworker5=1 if occupation5==1
replace Migrantworker5=0 if occupation5==2
replace Migrantworker5=0 if occupation5==3
replace Migrantworker5=0 if occupation5==4
replace Migrantworker5=0 if occupation5==5

replace Urbanworker5=0 if occupation5==1
replace Urbanworker5=1 if occupation5==2
replace Urbanworker5=0 if occupation5==3
replace Urbanworker5=0 if occupation5==4
replace Urbanworker5=0 if occupation5==5


replace Ruralworker5=0 if occupation5==1
replace Ruralworker5=0 if occupation5==2
replace Ruralworker5=1 if occupation5==3
replace Ruralworker5=0 if occupation5==4
replace Ruralworker5=0 if occupation5==5


replace Peasant5=0 if occupation5==1
replace Peasant5=0 if occupation5==2
replace Peasant5=0 if occupation5==3
replace Peasant5=1 if occupation5==4
replace Peasant5=0 if occupation5==5

replace Others5=0 if occupation5==1
replace Others5=0 if occupation5==2
replace Others5=0 if occupation5==3
replace Others5=0 if occupation5==4
replace Others5=1 if occupation5==5

/*create interaction terms*/
gen interFairMigrant=Migrantworker5*fairness
gen interFairUrban=Urbanworker5*fairness
gen interFairRural=Ruralworker5*fairness
gen interFairPeasant=Peasant5*fairness
gen interFairOthers=Others5*fairness

gen interincomefairMigrant=Migrantworker5*incomefair
gen interincomefairUrban=Urbanworker5*incomefair
gen interincomefairRural=Ruralworker5*incomefair
gen interincomefairPeasant=Peasant5*incomefair
gen interincomefairOthers=Others5*incomefair


gen intertrustCGMigrant=Migrantworker5*trustCG
gen intertrustCGUrban=Urbanworker5*trustCG
gen intertrustCGRural=Ruralworker5*trustCG
gen intertrustCGPeasant=Peasant5*trustCG
gen intertrustCGOthers=Others5*trustCG

gen intertrustLGMigrant=Migrantworker5*trustLG
gen intertrustLGUrban=Urbanworker5*trustLG
gen intertrustLGRural=Ruralworker5*trustLG
gen intertrustLGPeasant=Peasant5*trustLG
gen intertrustLGOthers=Others5*trustLG


gen intermarriedMigrant=Migrantworker5*married
gen intermarriedUrban=Urbanworker5*married
gen intermarriedRural=Ruralworker5*married
gen intermarriedPeasant=Peasant5*married
gen intermarriedOthers=Others5*married


gen Occupation=.
replace Occupation=1 if Migrantworker5==1
replace Occupation=2 if Urbanworker5==1
replace Occupation=3 if Ruralworker5==1
replace Occupation=4 if Peasant5==1
replace Occupation=5 if Others5==1


gen UTMigrant=Migrantworker5*unfairtreatment
gen UTUrban= unfairtreatment*Urbanworker5
gen UTRural= unfairtreatment*Ruralworker5
gen UTPeasant= unfairtreatment*Peasant5
gen UTOthers= unfairtreatment*Others5





/* Predicted Probabilities*/
logit Protest  i.Occupation age male education   minority income incomefair fairness  [pweight=WEIGHT]
margins, at( Occupation= (1 (1) 2) ) vsquish


logit Petition  i.Occupation age male education   minority income incomefair fairness  [pweight=WEIGHT]
margins, at( Occupation= (1 (1) 2) ) vsquish

/*Odds Ratio*/
logit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income incomefair fairness  [pweight=WEIGHT], or
logit Petition Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness  [pweight=WEIGHT], or


/*Table 6, Models with interaction terms*/

logit Protest Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers [pweight=WEIGHT]
est store model3

logit Petition Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers [pweight=WEIGHT]
est store model4





/*multilevel modeling*/
/*add prefectural ID into dataset*/
gen s411=.
replace s411= 1    if s42==1
replace s411= 2    if s42==2
replace s411= 3    if s42==3
replace s411= 4    if s42==4
replace s411= 5    if s42==5
replace s411= 6    if s42==6
replace s411= 7    if s42==7
replace s411= 8    if s42==8
replace s411= 9    if s42==9
replace s411= 10   if s42==10
replace s411= 11   if s42==11
replace s411= 12   if s42==12
replace s411= 13   if s42==13
replace s411= 14   if s42==14
replace s411= 15   if s42==15
replace s411= 16   if s42==16
replace s411= 17   if s42==17
replace s411= 18   if s42==18
replace s411= 19   if s42==19
replace s411= 19   if s42==20
replace s411= 19   if s42==21
replace s411= 19   if s42==22
replace s411= 19   if s42==23
replace s411= 19   if s42==24
replace s411= 19   if s42==25
replace s411= 20   if s42==26
replace s411= 21   if s42==27
replace s411= 21   if s42==28
replace s411= 22   if s42==29
replace s411= 23   if s42==30
replace s411= 23   if s42==31
replace s411= 24   if s42==32
replace s411= 25   if s42==33
replace s411= 26   if s42==34
replace s411= 27   if s42==35
replace s411= 28   if s42==36
replace s411= 29   if s42==37
replace s411= 30   if s42==38
replace s411= 31   if s42==39
replace s411= 32   if s42==40
replace s411= 33   if s42==41
replace s411= 34   if s42==42
replace s411= 35   if s42==43
replace s411= 35   if s42==44
replace s411= 36   if s42==45
replace s411= 37   if s42==46
replace s411= 37   if s42==47
replace s411= 37   if s42==48
replace s411= 38   if s42==49
replace s411= 39   if s42==50
replace s411= 40   if s42==51
replace s411= 41   if s42==52
replace s411= 42   if s42==53
replace s411= 43   if s42==54
replace s411= 43   if s42==55
replace s411= 43   if s42==56
replace s411= 44   if s42==57
replace s411= 45   if s42==58
replace s411= 46   if s42==59
replace s411= 46   if s42==60
replace s411= 47   if s42==61
replace s411= 47   if s42==62
replace s411= 48   if s42==63
replace s411= 49   if s42==64
replace s411= 50   if s42==65
replace s411= 50   if s42==66
replace s411= 51   if s42==67
replace s411= 52   if s42==68
replace s411= 53   if s42==69
replace s411= 54   if s42==70
replace s411= 55   if s42==71
replace s411= 56   if s42==72
replace s411= 57   if s42==73
replace s411= 57   if s42==74
replace s411= 58   if s42==75
replace s411= 59   if s42==76
replace s411= 60   if s42==77
replace s411= 61   if s42==78
replace s411= 62   if s42==79
replace s411= 63   if s42==80
replace s411= 64   if s42==81
replace s411= 65   if s42==82
replace s411= 66   if s42==83
replace s411= 67   if s42==84
replace s411= 68   if s42==85
replace s411= 68   if s42==86
replace s411= 69   if s42==87
replace s411= 70   if s42==88
replace s411= 71   if s42==89
replace s411= 72   if s42==90
replace s411= 73   if s42==91
replace s411= 74   if s42==92
replace s411= 75   if s42==93
replace s411= 76   if s42==94
replace s411= 77   if s42==95
replace s411= 78   if s42==96
replace s411= 78   if s42==97
replace s411= 79   if s42==98
replace s411= 80   if s42==99
replace s411= 81   if s42==100
replace s411= 82   if s42==101
replace s411= 83   if s42==102
replace s411= 84   if s42==103
replace s411= 85   if s42==104
replace s411= 86   if s42==105
replace s411= 87   if s42==106
replace s411= 88   if s42==107
replace s411= 89   if s42==108
replace s411= 90   if s42==109
replace s411= 91   if s42==110
replace s411= 92   if s42==111
replace s411= 93   if s42==112
replace s411= 94   if s42==113
replace s411= 95   if s42==114
replace s411= 96   if s42==115
replace s411= 97   if s42==116
replace s411= 98   if s42==117
replace s411= 99   if s42==118
replace s411= 100  if s42==119
replace s411= 101  if s42==120
replace s411= 102  if s42==121
replace s411= 103  if s42==122
replace s411= 104  if s42==123
replace s411= 105  if s42==124
replace s411= 106  if s42==125
replace s411= 107  if s42==126
replace s411= 107  if s42==127
replace s411= 107  if s42==128
replace s411= 108  if s42==129
replace s411= 109  if s42==130
replace s411= 110  if s42==131
replace s411= 111  if s42==132
replace s411= 112  if s42==133
replace s411= 113  if s42==134


gen Province=.
replace Province=s41/10000
gen Prefecture=.
replace Prefecture=s411
gen County=.
replace County=s42




melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income incomefair fairness  [pweight=WEIGHT] || Province: 
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income incomefair fairness  [pweight=WEIGHT] || Prefecture:
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income incomefair fairness  [pweight=WEIGHT] || County:

/*tried this out, and this worked*/
/*models */

logit   Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male   education   minority income  incomefair  fairness  [pweight=WEIGHT] 
est store Model1
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male   education   minority income  incomefair  fairness  [pweight=WEIGHT] || Province: 
est store Model2
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male   education   minority income  incomefair  fairness  [pweight=WEIGHT] || Prefecture:
est store Model3
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male   education   minority income  incomefair  fairness  [pweight=WEIGHT] || County:
est store Model4
outreg2 [Model1 Model2 Model3 Model4] using logit, alpha (0.001, 0.01, 0.05) word replace


logit Protest  i.Occupation age male education   minority income incomefair fairness  [pweight=WEIGHT]
margins, at( Occupation= (1 (1) 2) ) vsquish


melogit Protest  i.Occupation age male education   minority income incomefair fairness  [pweight=WEIGHT]|| Prefecture:
margins, at( Occupation= (1 (1) 2) ) vsquish






logit   Petition  Urbanworker5 Ruralworker5  Peasant5 Others5 age male   education   minority income  incomefair  fairness  [pweight=WEIGHT] 
est store Model5
melogit Petition  Urbanworker5 Ruralworker5  Peasant5 Others5 age male   education   minority income  incomefair  fairness  [pweight=WEIGHT] || Province: 
est store Model6
melogit Petition  Urbanworker5 Ruralworker5  Peasant5 Others5 age male   education   minority income  incomefair  fairness  [pweight=WEIGHT] || Prefecture:
est store Model7
melogit Petition  Urbanworker5 Ruralworker5  Peasant5 Others5 age male   education   minority income  incomefair  fairness  [pweight=WEIGHT] || County:
est store Model8
outreg2 [Model5 Model6 Model7 Model8] using logit, alpha (0.001, 0.01, 0.05) word replace


logit Petition  i.Occupation age male education   minority income incomefair fairness  [pweight=WEIGHT]
margins, at( Occupation= (1 (1) 2) ) vsquish








logit   Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male  education   minority income  incomefair  fairness  interFairUrban interFairRural interFairPeasant interFairOthers interincomefairUrban interincomefairRural interincomefairPeasant interincomefairOthers [pweight=WEIGHT] 
est store Model5
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male  education   minority income  incomefair  fairness  interFairUrban interFairRural interFairPeasant interFairOthers interincomefairUrban interincomefairRural interincomefairPeasant interincomefairOthers [pweight=WEIGHT] || Province: 
est store Model6
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male  education   minority income  incomefair  fairness  interFairUrban interFairRural interFairPeasant interFairOthers interincomefairUrban interincomefairRural interincomefairPeasant interincomefairOthers [pweight=WEIGHT] || Prefecture:
est store Model7
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male  education   minority income  incomefair  fairness  interFairUrban interFairRural interFairPeasant interFairOthers interincomefairUrban interincomefairRural interincomefairPeasant interincomefairOthers [pweight=WEIGHT] || County:
est store Model8
outreg2 [Model5 Model6 Model7 Model8] using logit, alpha (0.001, 0.01, 0.05) word replace









/*this one looks good*/
logit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers [pweight=WEIGHT] 
est store model2

logit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers interincomefairUrban interincomefairRural interincomefairPeasant interincomefairOthers [pweight=WEIGHT] 
est store model3

melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers interincomefairUrban interincomefairRural interincomefairPeasant interincomefairOthers [pweight=WEIGHT] || Province: 
est store model4

melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers  [pweight=WEIGHT] || Province: 
est store model5


/*multilevel models*/
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers   [pweight=WEIGHT] || Province: 
est store model5
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers   [pweight=WEIGHT] || Prefecture: 
est store model6
melogit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers   [pweight=WEIGHT] || County: 
est store model7



/*do likelihood ratio tests, then decided to keep model 1 and model 2*/
logit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness  
est store m1
logit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers 
est store m2
logit Protest  Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers interincomefairUrban interincomefairRural interincomefairPeasant interincomefairOthers 
est store m3

lrtest m1 m2
lrtest m2 m3
lrtest m1 m3


/*predict probabilities */
logit Protest Urbanworker5 Ruralworker5  Peasant5 Others5 age male education   minority income  incomefair  fairness interFairUrban interFairRural interFairPeasant interFairOthers [pweight=WEIGHT]
/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=0 Others5 =0 interFairUrban=0        interFairRural=0       interFairPeasant=0 interFairOthers=0  fairness=(1(1)5) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworke=0  Peasant5=0 Others5 =0 interFairUrban=(1(1)5)  interFairRural=0       interFairPeasant=0 interFairOthers=0  fairness=(1(1)5) ) atmeans vsquish
/*For Rural Worker*/
margin, at(Urbanworker5=0 Ruralworke=1  Peasant5=0 Others5 =0 interFairUrban=0        interFairRural=(1(1)5) interFairPeasant=0 interFairOthers=0  fairness=(1(1)5) ) atmeans vsquish
/*For Peasant*/
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=1 Others5 =0 interFairUrban=0        interFairRural=0       interFairPeasant=(1(1)5) interFairOthers=0  fairness=(1(1)5) ) atmeans vsquish
/*For Others*/
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=0 Others5 =1 interFairUrban=0        interFairRural=0       interFairPeasant=0 interFairOthers=(1(1)5)  fairness=(1(1)5) ) atmeans vsquish

marginsplot



/*let's start a new direction*/
gen IFMigrant=incomefair*Migrantworker5
gen IFUrban= incomefair*Urbanworker5
gen IFRural= incomefair*Ruralworker5
gen IFPeasant= incomefair*Peasant5
gen IFOthers= incomefair*Others5
gen FRMigrant=fairness*Migrantworker5
gen FRUrban= fairness*Urbanworker5
gen FRRural= fairness*Ruralworker5
gen FRPeasant= fairness*Peasant5
gen FROthers= fairness*Others5 





/*this are models for the ChenMason paper */
/*Protest is better than CA, so just use Protest (I have deleted CA)*/
logit Protest  age male education minority income  unfairtreatment fairness                                                                                [pweight=WEIGHT]
est store Model1
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5                                    [pweight=WEIGHT]
est store Model2
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5 UTUrban UTRural UTPeasant UTOthers [pweight=WEIGHT]
est store Model3
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5                                    FRUrban FRRural FRPeasant FROthers [pweight=WEIGHT]
est store Model4
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5 UTUrban UTRural UTPeasant UTOthers FRUrban FRRural FRPeasant FROthers [pweight=WEIGHT]
est store Model5

outreg2 [Model1 Model2 Model3 Model4 Model5] using logit, alpha (0.001, 0.01, 0.05) word replace




/*for R&R*/

/*let's try this out*/
gen UNFRMigrant=unfairness*Migrantworker5
gen UNFRUrban= unfairness*Urbanworker5
gen UNFRRural= unfairness*Ruralworker5
gen UNFRPeasant= unfairness*Peasant5
gen UNFROthers= unfairness*Others5 

gen IUFMigrant=incomeunfair*Migrantworker5
gen IUFUrban= incomeunfair*Urbanworker5
gen IUFRural= incomeunfair*Ruralworker5
gen IUFPeasant= incomeunfair*Peasant5
gen IUFOthers= incomeunfair*Others5


/*present all 5 models for RR3*/
logit Protest  age male education minority income  unfairtreatment unfairness                                                                                       [pweight=WEIGHT]
est store ModelA
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5                                           [pweight=WEIGHT]
est store ModelB
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UTUrban UTRural UTPeasant UTOthers       [pweight=WEIGHT]
est store ModelC
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UNFRUrban UNFRRural UNFRPeasant UNFROthers       [pweight=WEIGHT]
est store ModelD
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UTUrban UTRural UTPeasant UTOthers UNFRUrban UNFRRural UNFRPeasant UNFROthers     [pweight=WEIGHT]
est store ModelE


outreg2 [ModelA ModelB ModelC ModelD ModelE ] using logit, alpha (0.001, 0.01, 0.05) word replace



/*Do likelihood ratio test*/
logit Protest  age male education minority income  unfairtreatment unfairness                                                                                   
est store ModelAA
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5
est store ModelBB

logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UTUrban UTRural UTPeasant UTOthers       
est store ModelCC
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UNFRUrban UNFRRural UNFRPeasant UNFROthers       
est store ModelDD
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UTUrban UTRural UTPeasant UTOthers UNFRUrban UNFRRural UNFRPeasant UNFROthers    
est store ModelEE


lrtest ModelCC ModelEE
lrtest ModelDD ModelEE
lrtest ModelBB ModelEE




/*predict probabilities */
/*Model A*/
logit Protest  age male education minority income  unfairtreatment unfairness                                                                                       [pweight=WEIGHT]

margins, at( unfairtreatment= ( 0(1)1) ) atmeans vsquish
margins, at( unfairness= ( 1(1)5) ) atmeans vsquish
marginsplot

/*Model B*/
logit Protest  age male education minority income  unfairtreatment unfairness Urbanworker5 Ruralworker5  Peasant5 Others5   [pweight=WEIGHT]
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=0 Others5 =0 ) atmeans vsquish
margin, at(Urbanworker5=1 Ruralworke=0  Peasant5=0 Others5 =0 ) atmeans vsquish



/*Model C*/
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UTUrban UTRural UTPeasant UTOthers       [pweight=WEIGHT]
/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworker5=0  Peasant5=0 Others5=0 UTUrban=0 UTRural=0  UTPeasant=0 UTOthers=0  unfairtreatment=(0(1)1) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworker5=0  Peasant5=0 Others5 =0 UTUrban=1 UTRural=0  UTPeasant=0 UTOthers=0  unfairtreatment=(0(1)1) ) atmeans vsquish


/*Model D*/
logit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UNFRUrban UNFRRural UNFRPeasant UNFROthers       [pweight=WEIGHT]
/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworker5=0  Peasant5=0 Others5 =0 UNFRUrban=0      UNFRRural=0  UNFRPeasant=0  UNFROthers=0  unfairness=(1(1)5) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworker5=0  Peasant5=0 Others5 =0 UNFRUrban=(1(1)5)  UNFRRural=0 UNFRPeasant=0 UNFROthers=0  unfairness=(1(1)5) ) atmeans vsquish









/*relogit does not give a better result*/

relogit Protest  age male education minority income  unfairtreatment unfairness                                                                                       [pweight=WEIGHT]
est store REModelA
relogit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5                                           [pweight=WEIGHT]
est store REModelB
relogit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UTUrban UTRural UTPeasant UTOthers       [pweight=WEIGHT]
est store REModelC
relogit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UNFRUrban UNFRRural UNFRPeasant UNFROthers       [pweight=WEIGHT]
est store REModelD
relogit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UTUrban UTRural UTPeasant UTOthers UNFRUrban UNFRRural UNFRPeasant UNFROthers     [pweight=WEIGHT]
est store REModelE

outreg2 [REModelA REModelB REModelC REModelD REModelE ] using relogit, alpha (0.001, 0.01, 0.05) word replace

/*Model D*/
relogit Protest  age male education minority income  unfairtreatment unfairness  Urbanworker5 Ruralworker5  Peasant5 Others5  UNFRUrban UNFRRural UNFRPeasant UNFROthers       [pweight=WEIGHT]
/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworker5=0  Peasant5=0 Others5 =0 UNFRUrban=0      UNFRRural=0  UNFRPeasant=0  UNFROthers=0  unfairness=(1(1)5) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworker5=0  Peasant5=0 Others5 =0 UNFRUrban=(1(1)5)  UNFRRural=0 UNFRPeasant=0 UNFROthers=0  unfairness=(1(1)5) ) atmeans vsquish




/* Predicted Probabilities*/
/*model1*/
logit Protest  age male education minority income  unfairtreatment fairness   [pweight=WEIGHT]
margins, at( unfairtreatment= ( 0(1)1) ) atmeans vsquish
margins, at( fairness= ( 1(1)5) ) atmeans vsquish
marginsplot


/*model2*/
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5   [pweight=WEIGHT]
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=0 Others5 =0 ) atmeans vsquish
margin, at(Urbanworker5=1 Ruralworke=0  Peasant5=0 Others5 =0 ) atmeans vsquish

/*model3*/
logit Protest  age male education minority income  unfairtreatment unfairness Urbanworker5 Ruralworker5  Peasant5 Others5 UTUrban UTRural UTPeasant UTOthers [pweight=WEIGHT]
/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworker5=0  Peasant5=0 Others5 =0 UTUrban=0        UTRural=0       UTPeasant=0 UTOthers=0  unfairtreatment=(0(1)1) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworker5=0  Peasant5=0 Others5 =0 UTUrban=(1)  UTRural=0       UTPeasant=0 UTOthers=0  unfairtreatment=(0(1)1) ) atmeans vsquish


/*model4*/
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5 FRUrban FRRural FRPeasant FROthers [pweight=WEIGHT]
/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworker5=0  Peasant5=0 Others5 =0 FRUrban=0        FRRural=0       FRPeasant=0 FROthers=0  fairness=(1(1)5) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworker5=0  Peasant5=0 Others5 =0 FRUrban=(1(1)5)  FRRural=0       FRPeasant=0 FROthers=0  fairness=(1(1)5) ) atmeans vsquish


/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=0 Others5 =0 UTUrban=0        UTRural=0       UTPeasant=0       UTOthers=0        unfairtreatment=(0(1)1) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworke=0  Peasant5=0 Others5 =0 UTUrban=(0(1)1)  UTRural=0       UTPeasant=0       UTOthers=0        unfairtreatment=(0(1)1) ) atmeans vsquish
/*For Rural Worker*/
margin, at(Urbanworker5=0 Ruralworke=1  Peasant5=0 Others5 =0 UTUrban=0        UTRural=(0(1)1) UTPeasant=0       UTOthers=0        unfairtreatment=(0(1)1) ) atmeans vsquish
/*For Peasant*/
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=1 Others5 =0 UTUrban=0        UTRural=0       UTPeasant=(0(1)1) UTOthers=0        unfairtreatment=(0(1)1) ) atmeans vsquish
/*For Others*/
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=0 Others5 =1 UTUrban=0        UTRural=0       UTPeasant=0       UTOthers=(0(1)1)  unfairtreatment=(0(1)1) ) atmeans vsquish


/*odds ratio*/
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5 UTUrban UTRural UTPeasant UTOthers FRUrban FRRural FRPeasant FROthers [pweight=WEIGHT], or


marginsplot



 
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5                                         [pweight=WEIGHT]
logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5  FRUrban FRRural FRPeasant FROthers     [pweight=WEIGHT]
margin, at(fairness=(1(1)5) ) atmeans vsquish

logit Protest  age male education minority income  unfairtreatment fairness Urbanworker5 Ruralworker5  Peasant5 Others5  UTUrban UTRural UTPeasant UTOthers     [pweight=WEIGHT]
/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=0 Others5 =0 UTUrban=0        UTRural=0       UTPeasant=0       UTOthers=0        unfairtreatment=(0(1)1) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworke=0  Peasant5=0 Others5 =0 UTUrban=(0(1)1)  UTRural=0       UTPeasant=0       UTOthers=0        unfairtreatment=(0(1)1) ) atmeans vsquish
/*For Rural Worker*/

/*For Migrant Worker*/
margin, at(Urbanworker5=0 Ruralworke=0  Peasant5=0 Others5 =0 FRUrban=0        FRRural=0       FRPeasant=0 FROthers=0  fairness=(1(1)5) ) atmeans vsquish
/*For Urban Worker*/
margin, at(Urbanworker5=1 Ruralworke=0  Peasant5=0 Others5 =0 FRUrban=(1(1)5)  FRRural=0       FRPeasant=0 FROthers=0  fairness=(1(1)5) ) atmeans vsquish















